package com.cheems.cheemsspringaialibaba.Tools;

import org.springframework.ai.chat.model.ToolContext;
import org.springframework.ai.tool.annotation.Tool;

import java.util.Map;

//查询学生课表
public class SearchStudentSchedule {

    private final String appid = "nd9c7a7f4aea7c09c4";

    private final String secret = "2b27ac67656eb1c0d829dbe582cd7a03";

    @Tool(description = "查询课表")
    public String SearchStudentSchedule(ToolContext toolContext) {
        // 获取参数
        Map<String, Object> context = toolContext.getContext();
        String userName = (String)context.get("userName");
        String henauNumber = (String)context.get("henauNumber");
        String url = String.format("https://oauth.henau.edu.cn/oauth2_data_server/getstudschedule?appid=%s&secret=%s&user_name=%s&user_number=%s",
                appid, secret, userName, henauNumber);

        try {
            java.net.http.HttpClient client = java.net.http.HttpClient.newHttpClient();
            java.net.http.HttpRequest request = java.net.http.HttpRequest.newBuilder()
                    .uri(java.net.URI.create(url))
                    .POST(java.net.http.HttpRequest.BodyPublishers.noBody())
                    .build();
            java.net.http.HttpResponse<String> response = client.send(request, java.net.http.HttpResponse.BodyHandlers.ofString());
            return response.body()+"XN\t目标用户的学年，如“2009”表示2009-2010学年\n" +
                    "XQ_ID\t目标用户的学期ID，0第一学期，1第二学期，2第三学期\n" +
                    "USER_XH\t目标用户的学号\n" +
                    "XM\t目标用户的姓名\n" +
                    "USER_KCDM\t目标用户的课程代码\n" +
                    "KCMC\t目标用户的课程名称\n" +
                    "SKBJ\t目标用户的上课班级\n" +
                    "ZJJS_GH\t目标用户的教师工号\n" +
                    "ZJJS_XM\t目标用户的教师姓名\n" +
                    "STIMEZC\t目标用户的上课周次，如：1-5,8-18\n" +
                    "DSZ\t目标用户的上课单双周，1单周，2双周，0全周\n" +
                    "JCINFO\t目标用户的上课节次，如：1-2\n" +
                    "JCZ\t目标用户的上课大节，KXY格式，K为前缀，X表示星期几（7表示星期日），Y表示第几大节。如，K12表示星期一第二大节\n" +
                    "ROOM\t目标用户的上课地点\n" +
                    "ANALYSE\t目标用户的周次分析\n" +
                    "JCANALYSE\t目标用户的节次分析\n" +
                    "KCLB1MC\t目标用户的课程类别一\n" +
                    "KCLB2MC\t目标用户的课程类别二";
        } catch (Exception e) {
            return "查询失败: " + e.getMessage();
        }
    }
}
